'''
网格管理页面测试
'''

from Lib.base.page_object.dict_manager.dict_manager import DictManager
from selenium.webdriver.common.by import By
from Lib.common.get_data_by_mysql import MysqlAssert
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestDictManage.dictManager = DictManager(login)
    TestDictManage.assert_class = AssertClass(login)


@allure.feature('字段管理页面测试')
class TestDictManage:

    @classmethod
    def teardown_class(cls):
        # 删除大类
        delete_dict_big_type_sql = 'DELETE FROM info_dict_manage WHERE module_type = "UITEST01"'
        MysqlAssert().delete_data_by_sql(delete_dict_big_type_sql)

    @allure.title('新增字典主类')
    def test_1_create_dict_big_type(self):
        '''
        新增字典主类
        :return:
        '''
        self.dictManager.create_dict_big_type()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "添加成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='添加成功', context='新建字典大类')

    @allure.title('查看字典主类列表')
    def test_2_dict_big_type_list(self):
        '''
        查看字典大类列表
        :return:
        '''
        self.dictManager.big_dict_list()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "暂无数据")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='暂无数据', context='查看字典大类类别')

    @allure.title('修改字典主类')
    def test_3_big_dict_update(self):
        '''
        修改字典大类信息
        :return:
        '''
        self.dictManager.big_dict_update()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "更新成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='更新成功', context='更新字典大类')

    @allure.title('字典主类的停用和批量编辑')
    def test_4_big_dict_stop(self):
        '''
        字典大类的停用和批量编辑
        :return:
        '''
        self.dictManager.big_dict_stop()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "启用成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='启用成功', context='字典大类停用和批量启用')

    @allure.title('新建字典项')
    def test_5_create_dict_small_type(self):
        '''
        新建字典项
        :return:
        '''
        self.dictManager.create_dict_small_type()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "添加成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='添加成功', context='新建字典小类')

    @allure.title('查看字典项列表')
    def test_6_dict_small_type_list(self):
        '''
        查看小类列表
        :return:
        '''
        self.dictManager.dict_small_type_list()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "暂无数据")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='暂无数据', context='字典项列表查询')

    @allure.title('字典项排序和编辑')
    def test_7_small_type_update_and_sort(self):
        '''
        小类排序和编辑
        :return:
        '''
        self.dictManager.dict_small_type_update_and_sort()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "更新成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='更新成功', context='小类排序和编辑')

    @allure.title('字典项删除和停用')
    def test_8_dict_small_type_stop_and_delete(self):
        '''
        小类删除和停用
        :return:
        '''
        self.dictManager.dict_small_type_stop_and_delete()
        # 设置断言
        assert_arg = (By.XPATH, '//p[contains(text(), "删除成功")]')
        self.assert_class.make_assert_by_text(args=assert_arg, assert_data='删除成功', context='小类删除和停用')


if __name__ == '__main__':
    pytest.main(['-v', './dict_manager_test.py', '--alluredir', '../result', '--clean-alluredir'])
    os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    os.system('allure generate  ../result -o ../report/ --clean')
